import React,{ Component } from 'react'
import { connect } from 'react-redux'
import { init,validateToken } from '../actions/home'
import { disk_init } from '../actions/disk'
import Modal from '../components/HomeModal'
import Navbar from '../components/Navbar'
import Desktop from '../components/Desktop'

class Home extends Component {

  login = null

  constructor(props){
    super(props)
    this.login = this.props.home.login
  }

  componentWillMount(){
    const { dispatch } = this.props
    if (this.props.home.login === true && this.props.home.token !== null) {
      dispatch(validateToken(dispatch,this.props.home.token))
    }else {
      dispatch(init(this.props.dispatch))
      dispatch(disk_init(this.props.dispatch,this.props.home.token))
    }
  }

  render(){
    return(
      <div>
      <Navbar />
      <Desktop />
      <Modal />
      </div>
      )
  }
}

const mapStateToProps = (state) => {
  return{
    home: state.home
  }
}

export default connect(mapStateToProps)(Home)
